package Result;

import java.util.ArrayList;

public class ResultClassListClass implements Cloneable{
	
	ArrayList<ResultClass> resultsList;
	
	public ResultClassListClass()
	{
		resultsList = new ArrayList<ResultClass>();
	}
	
	public void addToResultsList(ResultClass r)
	{
		resultsList.add(r);	
	}
	
	public Object clone()
	{
		ResultClassListClass another = null;
		try
		{
			another = (ResultClassListClass) super.clone();
			// shallow copy made so far. Now we will make it deep
			another.resultsList = (ArrayList<ResultClass>) resultsList.clone();
		}
		catch(CloneNotSupportedException e) {e.printStackTrace();} 
		//This exception will not occur
	
		return another;
	}

	
	public double calculateAverageAccuracyObtainedFromWeka()
	{
		double sum=0.0;
		int numberOfResultsInTheList=resultsList.size();
		
		if(numberOfResultsInTheList==0)
		{
			System.out.println("ERROR: The list is free in calculateAverageAccuracyObtainedFromWeka");
			System.exit(0);
		}
		
		for(int i=0; i<resultsList.size(); i++)
			sum+=resultsList.get(i).evaluationResultOfWeka.pctCorrect();		
		
		return sum/numberOfResultsInTheList;
	}
	
	public double calculateAverageAccuracyObtained()
	{
		double sum=0.0;
		int numberOfResultsInTheList=resultsList.size();
		
		if(numberOfResultsInTheList==0)
		{
			System.out.println("ERROR: The list is free in calculateAverageAccuracyObtained");
			System.exit(0);
		}
		
		for(int i=0; i<resultsList.size(); i++)
			sum+=resultsList.get(i).getEvaluationResult().getMeasures().getAccuracy();		
		
		return sum/numberOfResultsInTheList;
	}
	
	/*****************************************************************
	* Function Name:	findErrorBar 
	* Aim:				find the error Bar  
	* Inputs:		 
	* Outputs:			*** 			
	* Data Structures: 	***
	* Algorithms: 		
	 * @throws Exception ***
	*****************************************************************/
	
	public double findErrorBarOfAccuracyResultsForWekaResults()
	{
		int numberOfResultsInTheList=resultsList.size();
		double[] accuracyList = new double[numberOfResultsInTheList] ;

		for(int i=0; i<numberOfResultsInTheList; i++)
			accuracyList[i] = resultsList.get(i).evaluationResultOfWeka.pctCorrect();		  

		return Utility.WorkerUtilityClass.findErrorBar(accuracyList);
	}
	
	/*****************************************************************
	* Function Name:	findErrorBar 
	* Aim:				find the error Bar  
	* Inputs:		 
	* Outputs:			*** 			
	* Data Structures: 	***
	* Algorithms: 		
	 * @throws Exception ***
	*****************************************************************/
	
	public double findErrorBarOfAccuracyResults()
	{
		int numberOfResultsInTheList=resultsList.size();
		double[] accuracyList = new double[numberOfResultsInTheList] ;

		for(int i=0; i<numberOfResultsInTheList; i++)
			accuracyList[i] = resultsList.get(i).getEvaluationResult().getMeasures().getAccuracy();		  

		return Utility.WorkerUtilityClass.findErrorBar(accuracyList);
	}
	
	public int size()
	{
		return resultsList.size();
	}
	
	public ResultClass get(int index)
	{
		return resultsList.get(index);
	}
	
	public void clear()
	{
		resultsList.clear();
	}
}
